package com.cskaoyan.controller.admin.mallcontroller;

import com.cskaoyan.bean.mallbean.Issue;
import com.cskaoyan.service.mallservice.IssueService;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.vo.mallvo.IssueListVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author hsp
 * @date 2021/5/10 20:41
 */
@RestController
@RequestMapping("admin/issue")
public class IssueController {
    @Autowired
    IssueService issueService;
    @RequiresPermissions("admin:issue:list")
    @RequestMapping("list")
    public BaseRespVo list(Integer page,Integer limit,String question,String sort,String order){


        IssueListVo  issueListVo = issueService.listIssue(page,limit,question,sort,order);

        return BaseRespVo.ok(issueListVo);
    }

    @RequiresPermissions("admin:issue:create")
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody Map map){
        String question = (String) map.get("question");
        String answer = (String) map.get("answer");

        Issue issue = issueService.createIssue(question,answer);
        return BaseRespVo.ok(issue);
    }

    @RequiresPermissions("admin:issue:update")
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Issue issue){


       Issue issueVo =  issueService.updateIssue(issue);

       return BaseRespVo.ok(issueVo);
    }

    @RequiresPermissions("admin:issue:delete")
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Map map){
        Integer id = (Integer) map.get("id");
        issueService.logicDeleteIssue(id);
        return BaseRespVo.ok();
    }
}
